#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QShortcut>
#include <QToolButton>
#include <QSpinBox>
#include <QLabel>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //菜单
    QMenu* editMenu=ui->menuBar->addMenu("编辑(&E)");
    QAction* action_copy=editMenu->addAction(QIcon("copy.png"),QString("复制&C"));
    //添加快捷键
    action_copy->setShortcut(QKeySequence("Ctrl+C"));
    ui->mainToolBar->addAction(action_copy);

    //对动作按钮进行分组
    QActionGroup* group=new QActionGroup(this);
    QAction* action_L=group->addAction("左对齐(&L)");
    QAction* action_R=group->addAction("右对齐(&R)");
    QAction* action_C=group->addAction("居中对齐(&C)");
    QAction* action_J=group->addAction("两端对齐(&J)");
    //对按钮进行可选
    action_L->setCheckable(true);
    action_R->setCheckable(true);
    action_C->setCheckable(true);
    action_J->setCheckable(true);

    editMenu->addSeparator();   //菜单栏中添加分割线
    editMenu->addAction(action_L);
    editMenu->addAction(action_R);
    editMenu->addAction(action_C);
    editMenu->addAction(action_J);

    //工具栏添加部件
    QToolButton* toolBtn=new QToolButton(this);
    toolBtn->setText("颜色");

    QMenu* colorMenu=new QMenu(this);
    colorMenu->addAction("红色");
    colorMenu->addAction("绿色");
    toolBtn->setMenu(colorMenu);
    toolBtn->setPopupMode(QToolButton::MenuButtonPopup);

    ui->mainToolBar->addWidget(toolBtn);

    QSpinBox* spingBox=new QSpinBox(this);
    ui->mainToolBar->addWidget(spingBox);

    //显示临时信息
    ui->statusBar->showMessage(QString("你好"),3000);

    //状态栏添加永久性部件
    QLabel *tag=new QLabel("永久性");
    ui->statusBar->addPermanentWidget(tag);



}

MainWindow::~MainWindow()
{
    delete ui;
}
